package com.card.server;

import java.util.List;

import javax.jdo.PersistenceManager;

import com.card.client.entry.OutputAccounts;
import com.card.client.service.OutputAccountsService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("unchecked")
public class OutputAccountsImpl extends RemoteServiceServlet implements
		OutputAccountsService {

	private static final long serialVersionUID = 3467609027034946019L;

	@Override
	public void addOutputAccounts(OutputAccounts outputAccounts) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		if(outputAccounts != null){
			pm.makePersistent(outputAccounts);
		}
		pm.close();
	}

	@Override
	public void delOutputAccounts(Long id) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		if(id != null){
			String query = "select from " + OutputAccounts.class.getName() + " where id == " + id;
			List<OutputAccounts> result = (List<OutputAccounts>)pm.newQuery(query).execute();
			OutputAccounts ia = result.get(0);
			pm.deletePersistent(ia);
		}
		pm.close();
	}

	@Override
	public OutputAccounts[] getAllOutputAccounts() {
		OutputAccounts[] result = null;
		PersistenceManager pm = PMF.get().getPersistenceManager();
		List<OutputAccounts> list = (List<OutputAccounts>)pm.newQuery(OutputAccounts.class).execute();
		if(list != null){
			result = new OutputAccounts[list.size()];
			for(int i=0;i<result.length;i++){
				result[i] = list.get(i);
			}
		} else {
			result = new OutputAccounts[0];
		}
		return result;
	}

	@Override
	public void updateOutputAccounts(OutputAccounts outputAccounts) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		if(outputAccounts != null){
			pm.makePersistent(outputAccounts);
		}
		pm.close();
	}

}
